package com.javademo.iotest;

import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Slf4j
public class InputStreamTest {
    public static void main(String[] args) {
        Path path = Paths.get("test.txt");
        try(InputStream inputStream = Files.newInputStream(path)) {
            log.info("inputSteam is {}", inputStream.getClass());
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        byte[] bytes = new byte[1024];
        try(InputStream inputFile = Files.newInputStream(path)){
            int len = inputFile.read(bytes);
            log.info("len:{}",len);
            log.info("bytes:{}", new String(bytes));
        }catch (IOException e){
            log.error("error:{}",e.getMessage(), e);
        }
    }
}
